// npm install jsencrypt

window = globalThis;

const JSEncrypt = require('jsencrypt');

// 正确的公钥和私钥（示例格式）
const PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMEkqM6HygDNNAJ5Y4dLKeeYmYC/qon6
XHMZclJS1wxn3DiTUoZE5y0+XKuUDphoFQdiDT7qyuczCFr8soxyL/MCAwEAAQ==
-----END PUBLIC KEY-----`;

const PRIVATE_KEY = `-----BEGIN PRIVATE KEY-----
MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAwSSozofKAM00Anlj
h0sp55iZgL+qifpccxlyUlLXDGfcOJNShkTnLT5cq5QOmGgVB2INPurK5zMIWvyy
jHIv8wIDAQABAkBH+4qyVmdRvyi4F1ehr8CxYO0sz8IWZGmaOAykY91j8JeV0RXb
QZ3GR0nbFxGJWXeNWUMVSp4H2bB3/qUK0WaBAiEA4+SjCtLGcc3BXP2yyHqp+xkg
2LFalrQXlvdyt/9C40ECIQDY9tlnQYyjmHkhPFGE/4k/Dnm289yTd7VtaMnvDIZq
MwIhAJAeFfGRS8fKa98H3VklIXvW70u6FOS7LTPedqDff4hBAiBKBVXAo51uxvs0
epa5UFErwS2HXIV5jlLIhAK42sYU/wIgN2R0cXLm/L1xe9mSTO4F8RAfnxWy5KZU
HHwWbpRzkGA=
-----END PRIVATE KEY-----`;

var encrypt = new JSEncrypt();
encrypt.setPublicKey(PUBLIC_KEY); // 设置公钥
var encrypted = encrypt.encrypt("hello Nexora"); // 对指定数据进行加密
console.log(encrypted);  // rrL9Puzz/IQPD7jFoLGlZg+eoxv3JkrEUDQ5iu3FNfcLGrcxgOp6p1s8VKQmTu0oaRF5M1TiQMRdEtlYrwPr2A==

// 使用私钥解密
var decrypt = new JSEncrypt();
decrypt.setPrivateKey(PRIVATE_KEY);  // 设置私钥
var uncrypted = decrypt.decrypt(encrypted); // 解密
console.log(uncrypted);